package Demo;

import java.util.Objects;

public class Animal implements Cloneable {
    private String name;

    public Animal(String name) {
        this.name = name;
    }

    @Override
    public Animal clone() throws CloneNotSupportedException {
        return (Animal) super.clone();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Animal animal = (Animal) o;
        return Objects.equals(name, animal.name);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(name);
    }
}
 class Test {
     public static void main(String[] args) {
         Animal animal = new Animal("张三");
         Animal animal1 = new Animal("张三");
         System.out.println(animal.equals(animal1));
          System.out.println(animal.hashCode());;
         System.out.println(animal1.hashCode());;
     }
    public static void main1(String[] args) throws CloneNotSupportedException {
        Animal animal = new Animal("  ");
        Animal animal2 = animal.clone();
        System.out.println(animal == animal2);
    }
}

